from django.db import models
from subscriber.models import PlatformSubscriber
from pang5_web.settings import PLATFORM_STATUS_PUBLISHING
from work.models import Works
from datetime import datetime


class Chapter(models.Model):
    id = models.AutoField(primary_key=True)
    works_id = models.ForeignKey(Works, on_delete=models.DO_NOTHING, verbose_name='作品id', db_constraint=False)
    name = models.CharField(verbose_name='章节名称', max_length=30)
    cover_img = models.TextField(verbose_name='封面地址')
    is_publish_clock = models.BooleanField(verbose_name='是否定时发布')
    publish_clock_time = models.CharField(verbose_name='定时发布时间', max_length=30)
    chapter_imgs = models.TextField(verbose_name='章节图片,多张', )
    status = models.IntegerField(verbose_name='发布状态', default=PLATFORM_STATUS_PUBLISHING)
    fail_reason = models.CharField(verbose_name='失败原因', max_length=60)
    ok_time = models.DateTimeField(verbose_name='上传成功时间', null=True, blank=True)
    create_time = models.DateTimeField(verbose_name='创建时间', default=datetime.now)
    update_time = models.DateTimeField(verbose_name='修改时间', default=datetime.now)
    next_time = models.CharField(verbose_name='下次发布', max_length=255,default='')

    class Meta:
        verbose_name = '章节信息表'

    def __str__(self):
        d = vars(self)
        d.pop('_state', '')
        return str(d)
